package com.lk.basic.service.impl;

import com.lk.basic.service.IFastdfsService;
import com.lk.basic.util.FastdfsUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class FastdfsServiceImpl implements IFastdfsService {

    @Value("${fastdfs.url}")
    private String fastdfsUrl;

    @Override
    public String upload(byte[] bytes, String extName) {
        String path = FastdfsUtil.upload(bytes, extName);
        return fastdfsUrl+path;
    }

    @Override
    public void delete(String path) {
        path=path.substring(fastdfsUrl.length()+1);
        int indexOf = path.indexOf("/");
        String groupName = path.substring(0, indexOf);
        String fileName = path.substring(indexOf + 1);
        FastdfsUtil.delete(groupName,fileName);


    }
}
